//
// Created by 11510 on 2024/6/20.
//

#include <iostream>
#include <string>
using std::cout;
using std::endl;


template<class T, int kCapacity = 10>
class Stack {
public:
    Stack() : _top(-1), _data(new T[kCapacity]()) {
        cout << "Stack()" << endl;
    }

    ~Stack() {
        if (_data) {
            delete[] _data;
            _data = nullptr;
        }
        cout << "~Stack()" << endl;
    }

    bool empty() const;

    bool full() const;

    void push(const T& t);

    void pop();

    T top();

private:
    int _top;
    T *_data;
};



template<class T, int kCapacity>
bool Stack<T, kCapacity>::empty() const {
    return _top == -1;
}

template<class T, int kCapacity>
bool Stack<T, kCapacity>::full() const {
    return _top == kCapacity - 1;
}

template<class T, int kCapacity>
void Stack<T, kCapacity>::push(const T &t){
    if(_top == kCapacity - 1){
        cout << "stack overflow" << endl;
        return;
    }
    _data[++_top] = t;
}

template<class T, int kCapacity>
 void Stack<T, kCapacity>::pop(){
    if(_top == -1){
        cout << "empty stack" << endl;
        return;
    }
    _top--;
}

template<class T, int kCapacity>
T Stack<T, kCapacity>::top(){
    if(_top == -1){
        throw "stack over flow";
    }
    return _data[_top];
}